package org.example.order.domain;

import lombok.Builder;
import lombok.Getter;

import java.math.BigDecimal;

@Getter
public class OrderDetail {
    private String id;
    private Product product;
    private BigDecimal price;
    private BigDecimal quantity;
    private BigDecimal amount;

    @Builder
    public OrderDetail(String id, Product product, BigDecimal price, BigDecimal quantity) {
        this.id = id;
        this.product = product;
        this.price = price;
        this.quantity = quantity;
        this.amount = calcAmount(price, quantity);
    }

    private BigDecimal calcAmount(BigDecimal price, BigDecimal quantity) {
        return price.multiply(quantity).setScale(price.scale(), BigDecimal.ROUND_HALF_UP);
    }
}
